//
//  MSImageAndTextCellContentView.m
//  MS
//
//  Created by Yuan on 13-2-26.
//  Copyright (c) 2013年 He Yuan. All rights reserved.
//

#import "MSImageAndTextCellContentView.h"
#import "UIImageView+WebCache.h"
#import <QuartzCore/QuartzCore.h>

#define kCELL_IMG_OFFSET_X 5.0

@implementation MSImageAndTextCellContentView
@synthesize txtLbl;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {        
        frame.size.width = kCELL_TXT_WIDTH + 2*kCELL_IMG_OFFSET_X;
        self.frame = frame;
        
        self.backgroundColor = [UIColor whiteColor];
        self.layer.borderWidth = 0.6f;
        self.layer.borderColor =[UIColor colorWithWhite:0.899 alpha:1.000].CGColor;
        
        CGRect imgFrame = CGRectMake(kCELL_IMG_OFFSET_X,kCELL_IMG_OFFSET_X,kCELL_TXT_WIDTH,kCELL_IMAGE_HEIGHT);
        contentImageView = [[UIImageView alloc]initWithFrame:imgFrame];
//        contentImageView.layer.borderWidth = 5.0f;
//        contentImageView.layer.borderColor =[UIColor colorWithWhite:1.0 alpha:1.0].CGColor;
        contentImageView.backgroundColor = [UIColor clearColor];
        [contentImageView setClipsToBounds:YES];
//        contentImage.layer.shadowRadius = 10;
//        contentImage.layer.shadowColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"cell_image_shadow"]].CGColor;
        
        //        contentImage.layer.masksToBounds = YES;
        //        contentImage.layer.cornerRadius = 6.0f;
        [contentImageView setContentMode:UIViewContentModeScaleAspectFill];
        [contentImageView setHidden:NO];
        [self addSubview:contentImageView];
        
        CGRect txtlblFrame = CGRectMake(imgFrame.origin.x, imgFrame.origin.y+imgFrame.size.height+3, imgFrame.size.width, 18);
        txtLbl = [[UILabel alloc]initWithFrame:txtlblFrame];
        [txtLbl setFont:FONT_NORMAL];
        [txtLbl setNumberOfLines:0];
        txtLbl.lineBreakMode = UILineBreakModeWordWrap;        
        [txtLbl setBackgroundColor:[UIColor clearColor]];
        [self addSubview:txtLbl];
        
        UIImage *bottomImg = [UIImage imageNamed:@"cell_image_shadow"];
        CGRect bottomImgFrame = CGRectMake(0,frame.size.height, frame.size.width,bottomImg.size.height);
        shadowView = [[UIImageView alloc]initWithFrame:bottomImgFrame];
        [shadowView setImage:bottomImg];
        [self addSubview:shadowView];
        
    }
    return self;
}

-(void)setTxtLblHeight:(CGFloat )height
{
    UIViewSetFrameHeight(txtLbl,height);
    UIViewSetFrameHeight(self, kCELL_IMAGE_HEIGHT + 2*kCELL_IMG_OFFSET_X + height);
    UIViewSetFrameY(shadowView, self.frame.size.height);
}

-(void)setFrame:(CGRect)frame
{
    [super setFrame:frame];
}

-(void)setContentImage:(NSString *)url
{
    [contentImageView setImageWithURL:[NSURL URLWithString:url]];
}

-(void)setText:(NSString *)txt
{
    [txtLbl setText:txt];
}

@end
